namespace Crux.Core.Websockets;
/// <summary>
/// WebSocketHandler
/// </summary>
public abstract class WebSocketHandler : IDisposableObservable
{
    /// <summary>
    ///  组代理
    /// </summary>
    public IGroupProxy? Groups { get; internal set; }
    /// <summary>
    /// 客户代理
    /// </summary>
    public IWebSocketClientProxy? Clients { get; internal set; }
    /// <summary>
    /// 是否已经释放了资源
    /// </summary>
    public bool IsDisposed { get; private set; }
    /// <summary>
    /// 已连接hook
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    public virtual Task OnConnectedAsync(WebSocketConnectionContext context) => Task.CompletedTask;
    /// <summary>
    /// 断开Hook
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    public virtual Task OnDisconnectedAsync(WebSocketConnectionContext context) => Task.CompletedTask;
    /// <summary>
    /// 处理文件
    /// </summary>
    /// <param name="context"></param>
    /// <param name="stream"></param>
    /// <returns></returns>
    public virtual Task HandleBinaryMessageAsync(WebSocketConnectionContext context, Stream stream) => Task.CompletedTask;
    /// <summary>
    ///
    /// </summary>
    protected virtual void Dispose(bool disposing)
    {
    }
    /// <summary>
    /// 释放
    /// </summary>
    public void Dispose()
    {
        if (IsDisposed) return;

        Dispose(true);
        IsDisposed = true;

        GC.SuppressFinalize(this);
    }

}